package com.bifrost.entity;

import com.bifrost.constant.CommentStatus;
import com.bifrost.constant.OrderStatus;

import java.io.Serializable;
import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
import java.math.BigInteger;
import java.util.List;


/**
 * The persistent class for the `ORDER` database table.
 */
@Entity
@Table(name = "ORDER_MAIN")
@NamedQuery(name = "Order.findAll", query = "SELECT o FROM Order o")
public class Order extends  BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 锁标志前缀
     * */
    public static final String LOCK_KEY_PERFIX="com.bifrost.order";

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ORDER_ID", unique = true, nullable = false)
    private Long orderId;

    @Column(name = "CARD_TYPE", length = 32)
    private String cardType;

    @Column(name = "CREDIT_CARD_CVV", length = 10)
    private String creditCardCvv;

    @Temporal(TemporalType.DATE)
    @Column(name = "CREDIT_CARD_EXPIRES")
    private Date creditCardExpires;

    @Column(name = "CREDIT_CARD_NUMBER", length = 32)
    private String creditCardNumber;

    @Column(name = "CREDIT_CARD_OWNER", length = 100)
    private String creditCardOwner;

    @Column(name = "CURRENCY_VALUE", precision = 10, scale = 5)
    private BigDecimal currencyValue;

    @Column(name = "CUSTOMER_AGREED")
    private Boolean customerAgreed;

    @Column(name = "CUSTOMER_MESSAGE", length = 255)
    private String customerMessage;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "DATE_PURCHASED")
    private Date datePurchased = new Date();

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "DELIVERY_CITY" ,foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private CountryArea deliveryCity;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "DELIVERY_COUNTRY" ,foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Country deliveryCountry;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "DELIVERY_DISTRICT" ,foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private CountryArea deliveryDistrict;

    @Column(name = "DELIVERY_LAST_NAME", length = 64)
    private String deliveryLastName;

    @Column(name = "DELIVERY_PHONE_SECONDARY", length = 32)
    private String deliveryPhoneSecondary;

    @Column(name = "DELIVERY_POSTCODE", length = 20)
    private String deliveryPostcode;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "DELIVERY_STATE" ,foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private CountryArea deliveryState;

    @Column(name = "DELIVERY_STREET")
    private String deliveryStreet;

    @Column(name = "DELIVERY_TELEPHONE_PRIMARY", length = 32)
    private String deliveryTelephonePrimary;

    @Column(name = "IP_ADDRESS", length = 128)
    private String ipAddress;

    @Column(name = "IS_CONFIRMED")
    private Boolean isConfirmed = Boolean.TRUE;

    @Column(name = "IS_BONUSPOINTS_USED")
    private Boolean isBonusPointsUsed = Boolean.FALSE;

    @Column(name = "ORDER_ADDRESS")
    private BigInteger orderAddress;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "ORDER_DATE_FINISHED")
    private Date orderDateFinished;

    @Column(name = "ORDER_NUMBER", length = 64)
    private String orderNumber;

    @Column(name = "CONSUME_NUMBMER", length = 64)
    private String consumeNumbmer;

    @Column(name = "OUT_TRADE_NO", length = 64)
    private String outTradeNo;

    @Column(name = "ORDER_STATUS", length = 32, nullable = false)
    private String orderStatus = OrderStatus.NEW;

    @Column(name = "SHIPPMENT_STATUS", length = 32)
    private String shippmentStatus;

    @Column(name = "COMMENT_STATUS", length = 32, nullable = false)
    private String commentStatus = CommentStatus.NOT_COMMENT;

    @Column(name = "ORDER_TOTAL", precision = 19, scale = 5)
    private BigDecimal orderTotal;

    @Column(name = "TOTAL_SHIPPING", precision = 19, scale = 5)
    private BigDecimal totalShippingFee;

    @Column(name = "TOTAL_OFFER", precision = 19, scale = 5)
    private BigDecimal totalOffer;

    @Column(name = "BONUS_POINTS_USED")
    private BigInteger bonusPointsUsed = BigInteger.ZERO;
    @Column(name = "TOTAL_BONUS_POINTS")
    private BigInteger totalBonusPoints = BigInteger.ZERO;

    @Column(name = "TOTAL_SERVICE", precision = 19, scale = 5)
    private BigDecimal totalService;

    @Column(name = "ORDER_SUBTOTAL", precision = 19, scale = 5)
    private BigDecimal subTotal;

    @Column(name = "ORDER_TYPE", length = 32)
    private String orderType;

    @Column(name = "SHIPPING_TYPE", length = 32)
    private String shippingType;

    @Column(name = "PAYMENT_MODULE_CODE", length = 32)
    private String paymentModuleCode;

    @Column(name = "SHIPPING_MODULE_CODE", length = 32)
    private String shippingModuleCode;

    @Column(name = "SERVICE_SHOP_ID")
    private Long serviceShop;
    @Column(name = "NEED_SERVICE")
    private Boolean needService = Boolean.FALSE;
    @Column(name = "NEED_INVOICE")
    private Boolean needInvoice = Boolean.FALSE;
    @Column(name = "INVOICE_TYPE", length = 32)
    private String invoiceType;
    @Column(name = "INVOICE_TITLE")
    private String invoiceTitle;
    @Column(name = "TAX_NUMBER")
    private String taxNumber;

    //优惠券订单所购买的优惠券的id
    @Column(name = "COUPON_ID")
    private Long couponId;

    @Column(name="PAY_STATUS")
    /** 支付状态，默认未支付0 */
    private Boolean isPaid = Boolean.FALSE;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="PAY_DATE")
    /** 支付时间 */
    private Date payDate;

    @Lob
    @Column(name = "DESCRIPTION")
    private String description;

    @Column(name = "CUSTOMER_CAR_NAME")
    private String customerCarName;

    //bi-directional many-to-one association to Customer
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CUSTOMER_ID" ,foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Customer customer;

    //bi-directional many-to-one association to MerchantStore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MERCHANT_ID" ,foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private MerchantStore merchantStore;

    @Column(name = "RELATED_ORDER_NUMBER", length = 32)
    private String relatedOrderNumber;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PAYMENT_TYPE" ,foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Payment payment;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "PREORDER_TIME")
    private Date preorderTime;

    @Column(name = "ISLOCKED")
    private Boolean isLocked = Boolean.FALSE;

    @Column(name = "IS_ARCHIVED")
    private Boolean archived = Boolean.FALSE;


    @Column(name = "IS_GIFTORDER")
    private Boolean isGiftOrder = Boolean.FALSE;

    @Column(name = "PRINT_COUNT")
    private Integer printCount = 0;

    //订单使用优惠券
    //bi-directional many-to-one association to OrderCoupon
    @OneToMany(mappedBy = "order", cascade = {CascadeType.ALL})
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<OrderCoupon> orderCoupons;

    //bi-directional many-to-one association to OrderItem
    @OneToMany(mappedBy = "order", cascade = {CascadeType.ALL})
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<OrderItem> orderItems;

    //bi-directional many-to-one association to OrderShipmentHistory
    @OneToMany(mappedBy = "order", cascade = {CascadeType.ALL})
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<OrderShipmentHistory> orderShipmentHistories;

    //bi-directional many-to-one association to OrderStatusHistory
    @OneToMany(mappedBy = "order")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<OrderStatusHistory> orderStatusHistories;

    //bi-directional many-to-one association to OrderTransaction
    @OneToMany(mappedBy = "order")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<OrderTransaction> orderTransactions;

    @OneToMany(mappedBy = "order", fetch = FetchType.LAZY)
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<OrderBundleItem> orderBundleItems;

    //bi-directional many-to-one association to MerchantAttribute
    @OneToMany(mappedBy = "order")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<OrderAttribute> orderAttributes;
    @Transient
    private String shippingOptions;



    public Order() {
    }

    public Order(Long orderId) {
        this.orderId = orderId;
    }

    public Order(Long orderId,BigDecimal orderTotal) {
        this.orderId = orderId;
        this.orderTotal  =orderTotal;
    }
    public Long getOrderId() {
        return this.orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public String getCardType() {
        return this.cardType;
    }

    public void setCardType(String cardType) {
        this.cardType = cardType;
    }

    public String getCreditCardCvv() {
        return this.creditCardCvv;
    }

    public void setCreditCardCvv(String creditCardCvv) {
        this.creditCardCvv = creditCardCvv;
    }

    public Date getCreditCardExpires() {
        return this.creditCardExpires;
    }

    public void setCreditCardExpires(Date creditCardExpires) {
        this.creditCardExpires = creditCardExpires;
    }

    public String getCreditCardNumber() {
        return this.creditCardNumber;
    }

    public void setCreditCardNumber(String creditCardNumber) {
        this.creditCardNumber = creditCardNumber;
    }

    public String getCreditCardOwner() {
        return this.creditCardOwner;
    }

    public void setCreditCardOwner(String creditCardOwner) {
        this.creditCardOwner = creditCardOwner;
    }

    public BigDecimal getCurrencyValue() {
        return this.currencyValue;
    }

    public void setCurrencyValue(BigDecimal currencyValue) {
        this.currencyValue = currencyValue;
    }

    public Boolean getCustomerAgreed() {
        return this.customerAgreed;
    }

    public void setCustomerAgreed(Boolean customerAgreed) {
        this.customerAgreed = customerAgreed;
    }

    public String getCustomerMessage() {
        return this.customerMessage;
    }

    public void setCustomerMessage(String customerMessage) {
        this.customerMessage = customerMessage;
    }

    public Date getDatePurchased() {
        return this.datePurchased;
    }

    public void setDatePurchased(Date datePurchased) {
        this.datePurchased = datePurchased;
    }

    public CountryArea getDeliveryCity() {
        return this.deliveryCity;
    }

    public void setDeliveryCity(CountryArea deliveryCity) {
        this.deliveryCity = deliveryCity;
    }

    public Country getDeliveryCountry() {
        return this.deliveryCountry;
    }

    public void setDeliveryCountry(Country deliveryCountry) {
        this.deliveryCountry = deliveryCountry;
    }

    public CountryArea getDeliveryDistrict() {
        return this.deliveryDistrict;
    }

    public void setDeliveryDistrict(CountryArea deliveryDistrict) {
        this.deliveryDistrict = deliveryDistrict;
    }

    public String getDeliveryLastName() {
        return this.deliveryLastName;
    }

    public void setDeliveryLastName(String deliveryLastName) {
        this.deliveryLastName = deliveryLastName;
    }

    public String getDeliveryPhoneSecondary() {
        return this.deliveryPhoneSecondary;
    }

    public void setDeliveryPhoneSecondary(String deliveryPhoneSecondary) {
        this.deliveryPhoneSecondary = deliveryPhoneSecondary;
    }

    public String getDeliveryPostcode() {
        return this.deliveryPostcode;
    }

    public void setDeliveryPostcode(String deliveryPostcode) {
        this.deliveryPostcode = deliveryPostcode;
    }

    public CountryArea getDeliveryState() {
        return this.deliveryState;
    }

    public void setDeliveryState(CountryArea deliveryState) {
        this.deliveryState = deliveryState;
    }

    public String getDeliveryStreet() {
        return this.deliveryStreet;
    }

    public void setDeliveryStreet(String deliveryStreet) {
        this.deliveryStreet = deliveryStreet;
    }

    public String getDeliveryTelephonePrimary() {
        return this.deliveryTelephonePrimary;
    }

    public void setDeliveryTelephonePrimary(String deliveryTelephonePrimary) {
        this.deliveryTelephonePrimary = deliveryTelephonePrimary;
    }

    public String getIpAddress() {
        return this.ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public Boolean getIsConfirmed() {
        return this.isConfirmed;
    }

    public void setIsConfirmed(Boolean isConfirmed) {
        this.isConfirmed = isConfirmed;
    }

    public BigInteger getOrderAddress() {
        return this.orderAddress;
    }

    public void setOrderAddress(BigInteger orderAddress) {
        this.orderAddress = orderAddress;
    }

    public Date getOrderDateFinished() {
        return this.orderDateFinished;
    }

    public void setOrderDateFinished(Date orderDateFinished) {
        this.orderDateFinished = orderDateFinished;
    }

    public String getOrderNumber() {
        return this.orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }

    public String getConsumeNumbmer() {
        return consumeNumbmer;
    }

    public void setConsumeNumbmer(String consumeNumbmer) {
        this.consumeNumbmer = consumeNumbmer;
    }

    public String getOutTradeNo() {
        return outTradeNo;
    }

    public void setOutTradeNo(String outTradeNo) {
        this.outTradeNo = outTradeNo;
    }

    public String getOrderStatus() {
        return this.orderStatus;
    }

    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    public BigDecimal getTotalService() {
        return totalService;
    }

    public void setTotalService(BigDecimal totalService) {
        this.totalService = totalService;
    }

    public BigDecimal getTotalShippingFee() {
        return totalShippingFee;
    }

    public void setTotalShippingFee(BigDecimal totalShippingFee) {
        this.totalShippingFee = totalShippingFee;
    }

    public BigDecimal getTotalOffer() {
        return totalOffer;
    }

    public void setTotalOffer(BigDecimal totalOffer) {
        this.totalOffer = totalOffer;
    }

    public Boolean isBonusPointsUsed() {
        return isBonusPointsUsed;
    }

    public void setIsBonusPointsUsed(Boolean bonusPointsUsed) {
        isBonusPointsUsed = bonusPointsUsed;
    }

    public void setBonusPointsUsed(BigInteger bonusPointsUsed) {
        this.bonusPointsUsed = bonusPointsUsed;
    }

    public BigInteger getBonusPointsUsed() {
        return this.bonusPointsUsed;
    }

    public BigDecimal getSubTotal() {
        return subTotal;
    }

    public void setSubTotal(BigDecimal subTotal) {
        this.subTotal = subTotal;
    }

    public Long getServiceShop() {
        return serviceShop;
    }

    public void setServiceShop(Long serviceShop) {
        this.serviceShop = serviceShop;
    }

    public Boolean isNeedService() {
        return needService;
    }

    public void setNeedService(Boolean needService) {
        this.needService = needService;
    }

    public Boolean getNeedInvoice() {
        return needInvoice;
    }

    public void setNeedInvoice(Boolean needInvoice) {
        this.needInvoice = needInvoice;
    }

    public String getInvoiceType() {
        return invoiceType;
    }

    public void setInvoiceType(String invoiceType) {
        this.invoiceType = invoiceType;
    }

    public String getInvoiceTitle() {
        return invoiceTitle;
    }

    public void setInvoiceTitle(String invoiceTitle) {
        this.invoiceTitle = invoiceTitle;
    }

    public String getTaxNumber() {
        return taxNumber;
    }

    public void setTaxNumber(String taxNumber) {
        this.taxNumber = taxNumber;
    }

    public BigDecimal getOrderTotal() {
        return this.orderTotal;
    }

    public void setOrderTotal(BigDecimal orderTotal) {
        this.orderTotal = orderTotal;
    }

    public String getOrderType() {
        return this.orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }

    public String getShippingType() {
        return shippingType;
    }

    public void setShippingType(String shippingType) {
        this.shippingType = shippingType;
    }

    public String getPaymentModuleCode() {
        return this.paymentModuleCode;
    }

    public void setPaymentModuleCode(String paymentModuleCode) {
        this.paymentModuleCode = paymentModuleCode;
    }

    public String getShippingModuleCode() {
        return this.shippingModuleCode;
    }

    public void setShippingModuleCode(String shippingModuleCode) {
        this.shippingModuleCode = shippingModuleCode;
    }

    public String getShippmentStatus() {
        return shippmentStatus;
    }

    public void setShippmentStatus(String shippmentStatus) {
        this.shippmentStatus = shippmentStatus;
    }

    public String getCommentStatus() {
        return commentStatus;
    }

    public void setCommentStatus(String commentStatus) {
        this.commentStatus = commentStatus;
    }

    public Customer getCustomer() {
        return this.customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public String getCustomerCarName() {
        return customerCarName;
    }

    public void setCustomerCarName(String customerCarName) {
        this.customerCarName = customerCarName;
    }

    public MerchantStore getMerchantStore() {
        return this.merchantStore;
    }

    public void setMerchantStore(MerchantStore merchantStore) {
        this.merchantStore = merchantStore;
    }

    public Payment getPayment() {
        return this.payment;
    }

    public void setPayment(Payment payment) {
        this.payment = payment;
    }

    public String getRelatedOrderNumber() {
        return relatedOrderNumber;
    }

    public void setRelatedOrderNumber(String relatedOrderNumber) {
        this.relatedOrderNumber = relatedOrderNumber;
    }

    public Date getPreorderTime() {
        return preorderTime;
    }

    public void setPreorderTime(Date preorderTime) {
        this.preorderTime = preorderTime;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<OrderCoupon> getOrderCoupons() {
        return this.orderCoupons;
    }

    public void setOrderCoupons(List<OrderCoupon> orderCoupons) {
        this.orderCoupons = orderCoupons;
    }

    public Long getCouponId() {
        return couponId;
    }

    public void setCouponId(Long couponId) {
        this.couponId = couponId;
    }

    public OrderCoupon addOrderCoupon(OrderCoupon orderCoupon) {
        getOrderCoupons().add(orderCoupon);
        orderCoupon.setOrder(this);

        return orderCoupon;
    }

    public OrderCoupon removeOrderCoupon(OrderCoupon orderCoupon) {
        getOrderCoupons().remove(orderCoupon);
        orderCoupon.setOrder(null);

        return orderCoupon;
    }

    public List<OrderItem> getOrderItems() {
        return this.orderItems;
    }

    public void setOrderItems(List<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    public OrderItem addOrderItem(OrderItem orderItem) {
        getOrderItems().add(orderItem);
        orderItem.setOrder(this);

        return orderItem;
    }

    public OrderItem removeOrderItem(OrderItem orderItem) {
        getOrderItems().remove(orderItem);
        orderItem.setOrder(null);

        return orderItem;
    }

    public List<OrderShipmentHistory> getOrderShipmentHistories() {
        return this.orderShipmentHistories;
    }

    public void setOrderShipmentHistories(List<OrderShipmentHistory> orderShipmentHistories) {
        this.orderShipmentHistories = orderShipmentHistories;
    }

    public OrderShipmentHistory addOrderShipmentHistory(OrderShipmentHistory orderShipmentHistory) {
        getOrderShipmentHistories().add(orderShipmentHistory);
        orderShipmentHistory.setOrder(this);

        return orderShipmentHistory;
    }

    public OrderShipmentHistory removeOrderShipmentHistory(OrderShipmentHistory orderShipmentHistory) {
        getOrderShipmentHistories().remove(orderShipmentHistory);
        orderShipmentHistory.setOrder(null);

        return orderShipmentHistory;
    }

    public List<OrderStatusHistory> getOrderStatusHistories() {
        return this.orderStatusHistories;
    }

    public void setOrderStatusHistories(List<OrderStatusHistory> orderStatusHistories) {
        this.orderStatusHistories = orderStatusHistories;
    }

    public OrderStatusHistory addOrderStatusHistory(OrderStatusHistory orderStatusHistory) {
        getOrderStatusHistories().add(orderStatusHistory);
        orderStatusHistory.setOrder(this);

        return orderStatusHistory;
    }

    public OrderStatusHistory removeOrderStatusHistory(OrderStatusHistory orderStatusHistory) {
        getOrderStatusHistories().remove(orderStatusHistory);
        orderStatusHistory.setOrder(null);

        return orderStatusHistory;
    }

    public List<OrderTransaction> getOrderTransactions() {
        return this.orderTransactions;
    }

    public void setOrderTransactions(List<OrderTransaction> orderTransactions) {
        this.orderTransactions = orderTransactions;
    }

    public OrderTransaction addOrderTransaction(OrderTransaction orderTransaction) {
        getOrderTransactions().add(orderTransaction);
        orderTransaction.setOrder(this);

        return orderTransaction;
    }

    public OrderTransaction removeOrderTransaction(OrderTransaction orderTransaction) {
        getOrderTransactions().remove(orderTransaction);
        orderTransaction.setOrder(null);

        return orderTransaction;
    }

    public List<OrderBundleItem> getOrderBundleItems() {
        return orderBundleItems;
    }

    public void setOrderBundleItems(List<OrderBundleItem> orderBundleItems) {
        this.orderBundleItems = orderBundleItems;
    }

    public Boolean getLocked() {
        return isLocked;
    }

    public void setLocked(Boolean locked) {
        isLocked = locked;
    }

    public Boolean getGiftOrder() {
        return isGiftOrder;
    }

    public void setGiftOrder(Boolean giftOrder) {
        isGiftOrder = giftOrder;
    }

    public Boolean getArchived() {
        return archived;
    }

    public void setArchived(Boolean archived) {
        this.archived = archived;
    }

    public List<OrderAttribute> getOrderAttributes() {
        return orderAttributes;
    }

    public void setOrderAttributes(List<OrderAttribute> orderAttributes) {
        this.orderAttributes = orderAttributes;
    }

    public String getShippingOptions() {
        return shippingOptions;
    }

    public void setShippingOptions(String shippingOptions) {
        this.shippingOptions = shippingOptions;
    }

    public BigInteger getTotalBonusPoints() {
        return totalBonusPoints;
    }

    public void setTotalBonusPoints(BigInteger totalBonusPoints) {
        this.totalBonusPoints = totalBonusPoints;
    }

    public Boolean getPaid() {
        return isPaid;
    }

    public void setPaid(Boolean paid) {
        isPaid = paid;
    }

    public Date getPayDate() {
        return payDate;
    }

    public void setPayDate(Date payDate) {
        this.payDate = payDate;
    }

    public Integer getPrintCount() {
        return printCount;
    }

    public void setPrintCount(Integer printCount) {
        this.printCount = printCount;
    }
}